<%@ page language="java" import="java.util.*" contentType="text/html"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>新增问卷</title>
	<script charset="utf-8" src='<c:url value="/js/jquery.min.js"></c:url>'></script>
	<script src='<c:url value="/js/boot.js"></c:url>'></script>
	<script src='<c:url value="/js/rqfui/rqfui.js"></c:url>'></script>
	<style>
		html,body{
			margin: 0;
			padding: 0;
			font-family: "微软雅黑";
		}
		li{
			list-style: none;
		}
		a{
			text-decoration: none;
		}
		.Basic_course_content{
			width: 1920px;
			width: 100%;
		}
		.Basic_course_content_content{
			width: 1280px;
			margin: 0 auto;
		}
		.Basic_course_content_content_content{
			width: 780px;
 		    margin-left: 104px;
    		margin-top: 24px;
			text-align: left;
		}
		.Basic_course_content_content_content_title{
			color: #b8b8b8;
			font-size: 16px;
			padding-bottom: 1px;
			border-bottom: 2px solid #2459aa;
			font-weight: 800;
		}
		.Basic_course_content_content_content_title ul{
			padding:0;
			margin:10px;
		}
		.Basic_course_content_content_content_title li{
			display: inline-block;
			margin-right: 55px;
		}
		.Basic_course_content_content_content_title div{
			display: inline-block;
			height: 20px;
			width: 20px;
			border-radius: 50%;
			background: #b8b8b8;
		}
		.Basic_course_content_content_content_title li>div>span{
			color:white;
			z-index:1;
			position:relative;
			left:6px;
			top:-2px;
			font-weight:800;
			font-size:13px;
		}
		.Basic_course_content_content_content_content{
			padding: 25px 0;
		}
		.Basic_course_content_content_content_content>ul>li{
			padding: 16px 0;
		}
		.Basic_course_content_content_content_content>ul{
			margin: 0;
			padding: 0;
			margin-bottom: 16px;
		}
		.Basic_course_content_content_content_content>ul>li>div>span{
			/*float: left;*/
			font-size: 16px;
			padding: 4px 0;
		}
		.Basic_course_content_content_content_content>ul>li>div>span>font{
			color: #ff0000;
		}
		.Basic_course_content_content_content_content>ul>li>div>input{
			width: 420px;
			padding: 5px 0;
			padding-left: 5px;
		}
		.Basic_course_content_content_content_content>ul>li>div>select{
			padding: 5px 0;
			padding-left: 5px;
		}
		.Basic_course_content_content_content_content>ul>li>div>textarea{
			width: 420px;
			padding: 5px;
    		margin-top: 5px;
		}
		.Basic_course_content_content_content_content>ul>li>div>select>option{
			padding: 3px;
		}
		.Basic_course_baocun{
			width: 78px;
			height: 32px;
			text-align: center;
			background: #2459aa;
			color: #fff;
			font-size: 16px;
			line-height: 32px;
			border-radius: 3px;
			margin-left: 92px;
			display: inline-block;
			margin-right: 30px;
			cursor: pointer;
		}

	</style>
</head>
<body>
	<div class="Basic_course_content">
		<div class="Basic_course_content_content">
			<div class="Basic_course_content_content_content">
				<div class="Basic_course_content_content_content_title">
					<ul>
						<li style="color:#2459aa;">
							<div style="color:#2459aa;background:#2459aa;"><span style="">1</span></div>
							<span>新建问卷</span>
						</li>
						<li>
							<div><span>2</span></div>
							<span>问卷组装</span>
						</li>
						<li>
							<div><span>3</span></div>
							<span>配置用户</span>
						</li>
					</ul>
				</div>
				<div class="Basic_course_content_content_content_content">
					<ul>
						<li>
							<div>
								<span><font>*</font> 问卷名称：</span>
								<input type="text" id = "paperName" />
							</div>
						</li>
						<li>
							<div>
								<span><font>*</font> 调研方向：</span>
								<input type="text" id = "direction">
							</div>
						</li>
						<li>
							<div>
								<span><font>*</font> 调研规模：</span>
								<input type="text" id ="scale">
							</div>
						</li>
					</ul> 
					<a class="Basic_course_baocun" href="javascript:save()">保存</a> <a
						class="Basic_course_baocun" href="javascript:next()">下一步</a>
				</div>
			</div>

		</div>
	</div>
</body>
<script type="text/javascript">
	var rootPath = '${rootPath}';
	var paperId = '${paperId}';
	var isSave = false;
	var add_flag = true;
	$(function(){
		if(paperId){
			getMap(paperId);
			add_flag = false;
		}
	})
	
	function getMap(id){
		var url = rootPath +"/surveyPaper/map/" + id;
		$.ajax({
			url:url,
			method:"post",
			dataType:"json",
			data:{},
			success:function(data){
				if(data){
					$("#paperName").val(data.name);//试卷名称
					$("#direction").val(data.direction);//试卷名称
					$("#scale").val(data.scale);//试卷名称
				}
			},
			error:function(){
				mini.alert("获取信息失败");
			}
		});
	}
	function save(callBackfunction) {
		var url=rootPath;
		if(add_flag){
			url += "/surveyPaper/add";
		}else{
			url += "/surveyPaper/update/"+paperId;
		}
		var paperName = $("#paperName").val();//问卷名称
		if (!paperName) {
			mini.alert("请填写问卷名称！");
			return;
		}
		var direction = $("#direction").val();//调研方向
		if (!direction) {
			mini.alert("请填写调研方向！");
			return;
		}
		var scale = $("#scale").val();
		if(!scale){
			mini.alert("请填写调研规模！");
			return;
		}
		var map = new Object;
		map.name = paperName;
		map.direction = direction;
		map.scale = scale;
		var jsonData = JSON.stringify(map);
		$.ajax({
			url : url,
			method : "post",
			dataType : "json",
			data : {
				'data' : jsonData
			},
			success : function(data) {
				if (data) {
					isSave = true;
					if(!paperId){
						paperId = data.oid;
					}
					if (callBackfunction) {
						callBackfunction();
					}else{
						mini.alert("保存成功！");
					}
				}
			},
			error : function() {
				mini.alert("失败!");
			},
			complete : function() {
	
			}
		});
	}
	
	function next() {
		if(isSave){
			location.href = rootPath + "/surveyPaper/packages/"+ paperId;
		}else{
			save(function() {
				location.href = rootPath + "/surveyPaper/packages/" + paperId;
			});
		}
	}
</script>
</html>